package com.es.system.controller;

import com.es.api.SystemResult;
import com.es.system.domain.SysOperateLog;
import com.es.system.service.SysOperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 用户操作日志 前端控制器
 * </p>
 *
 * @author everysucceed
 * @since 2021-12-06
 */
@Controller
@RequestMapping("/system/operateLog")
public class SysOperateLogController {

    @Autowired
    private SysOperateLogService service;

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/manage")
    public String manage(){
        return "system/operateLog/manage";
    }

    @GetMapping("/operateLogs")
    @ResponseBody
    public SystemResult<SysOperateLog> operateLog(Integer page, Integer limit){
        if(null == page){
            page = 1;
        }
        if(null == limit){
            limit = 15;
        }
        SystemResult<SysOperateLog> systemResult = service.pages(page,limit);
        redisTemplate.opsForValue().set("oacs:system:logs",systemResult.getData());
        redisTemplate.opsForValue().set("oacs:system:logs-timeout",systemResult.getData(),2, TimeUnit.MINUTES);

        return systemResult;
    }

}
